/**
 * Angular JS 登录
 * Created by yangyan on 2015/5/9 .
 */
var loginModule = angular.module('LoginModule', [])
    .controller('LoginController', ['$scope', '$http', function ($scope, $http) {
        $scope.email = "y.os@qq.com";
        $scope.password = "";
        $scope.login = function (email, password, captcha) {
            var $scope = this;
            this.error = null;
            $http.post('/admin/login.do', {
                username: email,
                password: password,
                captcha: captcha
            }, {
                headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                transformRequest: function (data) {
                    return $.param(data);
                }
            }).success(function (data, status, headers, config) {
                if (data.success) {
                    location.href = "/admin/frame.do";
                } else {
                    $scope.error = data.msg;
                    $scope.refreshCaptcha();

                }
            }).error(function (data, status, headers, config) {
                $scope.error = data.msg || "错误";
            });
        };
        $scope.refreshCaptcha = function () {
            $scope.captchaUrl = '../captcha.png?_t=' + new Date().getTime();
            $scope.captcha = "";
        };
        $scope.refreshCaptcha();
    }]);